package com.cxp.serverdemo.config;

import com.cxp.serverdemo.bean.sys.bean.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class ContextUtil {

    public static User getLoginUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return authentication != null && authentication.getPrincipal() instanceof User ? (User)authentication.getPrincipal() : null;
    }

    public static String getLoginUsername() {
        User user = getLoginUser();
        return user != null ? user.getUsername() : null;
    }
}
